console.log(11111111111111)
const express = require('express')
const ClassesModel = require('../ClassesSchema')
const router =express.Router()
//http://localhost:3000/mongo/add
router.get('/add',(req, res) => {
    let clazz =new  ClassesModel({
        name:'田兴宇',
        age:28,
        sex:'男',
        hobby:['篮球','跑步']
    })
    clazz.save(function (err,result){
        if(err){
            res.json({
                code:1001,
                msg:'插入数据失败'
            })
        }else{
            res.json({
                code:1002,
                msg:'插入数据成功',
                data:result
            })
        }
    })
})
// 查找
router.get('/find',(req, res) => {
  if(req.query){
    delete req.query.page
    delete req.query.limit
  }
  ClassesModel.find(req.query,function (err,result){
      if(err){
          res.json({
              code:1001,
              msg:'查找数据失败'
          })
      }else{
          res.json({
              code:200,
              msg:'查找数据成功',
              data:result
          })
      }
  })
})
module.exports=router;
